package com.test4;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.worktool.RestExecutor;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.client.RestTemplate;

public class Test3 {

    private static RestTemplate restTemplate = RestExecutor.build();

    private static String robot = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=4c85d839-413b-42ce-9447-9fcc81c9f63c";

    public static void main(String[] args) {

        String jsonStr = "{\"title\":\"测试图文描述描述描述描述描述描述描述描述一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十\",\"description\":\"描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十\",\"url\":\"www.baidu.com\"}";

        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type","application/json");

        JSONObject param = new JSONObject();
        param.put("msgtype","news");

        JSONObject news = new JSONObject();

        JSONObject info = JSONObject.parseObject(jsonStr);
        JSONArray articles = new JSONArray();
        articles.add(info);
        news.put("articles",articles);
        param.put("news",news);

        HttpEntity<JSONObject> formEntity_1 = new HttpEntity<>(param,headers);
        JSONObject resultJSON_1 = restTemplate.postForObject(robot, formEntity_1, JSONObject.class);
        System.out.println("图文消息："+resultJSON_1);

    }

}
